<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Baner filter form base class.
 *
 * @package    alika
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseBanerFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'file_path'          => new sfWidgetFormFilterInput(),
      'created_at'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'updated_at'         => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'pub'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'user_id'            => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
      'title'              => new sfWidgetFormFilterInput(),
      'url'                => new sfWidgetFormFilterInput(),
      'see'                => new sfWidgetFormFilterInput(),
      'click'              => new sfWidgetFormFilterInput(),
      'position_id'        => new sfWidgetFormPropelChoice(array('model' => 'BanerPosition', 'add_empty' => true)),
      'material_id'        => new sfWidgetFormPropelChoice(array('model' => 'Material', 'add_empty' => true)),
      'width'              => new sfWidgetFormFilterInput(),
      'height'             => new sfWidgetFormFilterInput(),
      'region_id'          => new sfWidgetFormPropelChoice(array('model' => 'Region', 'add_empty' => true)),
      'is_folder'          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'baner2_folder_list' => new sfWidgetFormPropelChoice(array('model' => 'Folder', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'file_path'          => new sfValidatorPass(array('required' => false)),
      'created_at'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'updated_at'         => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'pub'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'user_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'sfGuardUser', 'column' => 'id')),
      'title'              => new sfValidatorPass(array('required' => false)),
      'url'                => new sfValidatorPass(array('required' => false)),
      'see'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'click'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'position_id'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'BanerPosition', 'column' => 'id')),
      'material_id'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Material', 'column' => 'id')),
      'width'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'height'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'region_id'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Region', 'column' => 'id')),
      'is_folder'          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'baner2_folder_list' => new sfValidatorPropelChoice(array('model' => 'Folder', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('baner_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addBaner2FolderListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(Baner2FolderPeer::BANER_ID, BanerPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(Baner2FolderPeer::FOLDER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(Baner2FolderPeer::FOLDER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Baner';
  }

  public function getFields()
  {
    return array(
      'id'                 => 'Number',
      'file_path'          => 'Text',
      'created_at'         => 'Date',
      'updated_at'         => 'Date',
      'pub'                => 'Boolean',
      'user_id'            => 'ForeignKey',
      'title'              => 'Text',
      'url'                => 'Text',
      'see'                => 'Number',
      'click'              => 'Number',
      'position_id'        => 'ForeignKey',
      'material_id'        => 'ForeignKey',
      'width'              => 'Number',
      'height'             => 'Number',
      'region_id'          => 'ForeignKey',
      'is_folder'          => 'Boolean',
      'baner2_folder_list' => 'ManyKey',
    );
  }
}
